// 提示框常用状态
export const DialogTitle = {
  ADD: 0,
  EDIT: 1,
  SEE: 2,

  properties: {
    0: { name: '添加' },
    1: { name: '修改' },
    2: { name: '查看' }

  },
  getEnumName
}

// 设备状态枚举  1.运行 2.停机 3.保养 4.维修 5.故障
export const DeviceEnum = {
  OPERATION: 1,
  SHUTDOWN: 2,
  MAINTAIN: 3,
  REPAIR: 4,
  FAULT: 5,
  properties: {
    1: { name: '运行', color: '#67C23A' },
    2: { name: '停机', color: '#909399' },
    3: { name: '保养', color: '#E6A23C' },
    4: { name: '维修', color: '#f53934' },
    5: { name: '故障', color: '#F56C6C' }
  },

  /**
   * @param id
   */
  getEnumName,
  getArray

}

/**
 * 获取枚举名称
 * @param id 枚举id
 * @returns {string|*}
 */
function getEnumName(id) {
  if (!this.properties[id]) {
    return '未知状态'
  }
  return this.properties[id].name
}

/**
 * 将对象转换数组
 * @returns {Array|*}
 */
function getArray() {
  const ary = []
  for (const key in this.properties) {
    if (this.properties.hasOwnProperty(key)) {
      ary.push({
        id: Number(key),
        ...this.properties[key]
      })
    }
  }
  return ary
}
